#!/bin/sh
# Doitall.bet file for North Atlantic ALB, created on May 15, 2013. 
# Just updated to accomodate split in TAI fishery - all other estimations the same as 2009 4B run
#--------------------------------------
#  PHASE 0  - Create initial par file
#--------------------------------------
#
if [ ! -f 00.par ]; then
   ./mfcl.exe albN.frq albN.ini 00.par -makepar
fi
# ---------
#  PHASE 1 
# ---------
if [ ! -f 01.par ]; then
   ./mfcl.exe albN.frq 00.par 01.par  -file - <<PHASE1
    -1  13 100      # standardised CPUE
    -2  13 100      # standardised CPUE
    -3  13 100      # standardised CPUE
    -4  13 10      # unstandardised CPUE
    -5  13 100      # standardised CPUE
    -6  13 1       # standardised CPUE but transitional cpues removed
    -7  13 100      # standardised CPUE
    -8  13 100       # standardised CPUE 
    -9  13 1       # standardised CPUE but transitional cpues removed 
    -10 13 100       # standardised CPUE 
    -11  13 1      # unstandardised CPUE
    -12  13 1      # unstandardised CPUE
#  Fisheries with non-decreasing selectivity with age
   -5  16   1      # 
   -8  16   1      # 
   -9  16   1      # 
   -10 16   1
   -11 16   1
  -999  26   2      # Use length-based selectivity
#use cubic spline for selectivity for non-LL
# -999 57 3	# functional form for selectivity
# -999 61 4      # number of parameters in cubic spline
# selectivity grouping - all fleets given unique selectivity
    -1  24   1      # 
    -3  24   3      # 
    -2  24   2      # 
    -4  24   4      # 
   -12  24   4      # 
    -5  24   5      # 
    -6  24   6      # 
    -7  24   7      # 
    -8  24   8      # 
    -9  24   9
    -10 24   10 
    -11  24  10      # 
# grouping of fisheries for catchability even if unique
    -1  29    1
    -2  29    2
    -3  29    3
    -4  29    4
    -5  29    5
    -6  29    6
    -7  29    7
    -8  29    8
    -9  29    9
    -10 29    10
    -11 29    11
    -12 29    12
# weighting the number of size data
    -1  49  10        	# divide BB and TR by 10 
    -2  49  10        	# "
    -3  49  10        	# "
    -4  49  10       	# "
    -5  49  10       	# divide JLL by 10
    -6  49  10        	# "
    -7  49  10       	# "
    -8  49  10        	# divide Ch Tai and Kor Pa LL by 10
    -9  49  10		# divide Ch Tai and Kor Pa LL by 10
    -10 49  10		# divide Ch Tai and Kor Pa LL by 10
    -11  49  1000      		# switch off these LL 
    -12  49  1000        	# switch off other surf
# Control paramaters
     1  32   4        # "Fast" initial fit(set initial estimation with exploitation rate constraint) 
     2 113   1        # estimate initpop/totpop scaling parameter
     1 141   3        # Robust normal likelihood function for LF data
     2  57   1        # Set recruitment one per year
     2  93   1        # Sets no. of recruitments per year to 1
     2  94   2        # Estimate initial population based on average Z 
     2  95   10        # Use average Z for first 30 years for equil. init. pop. 
     1 186   1	      # write all outputs
#     1 187   1
     1 188   1
     1 189   1        
     1 190   1        
  -999  14  10        # sets maximum incident fmort to 1.0
#       1  12   0        # estimate mean length of first age class
       1  13   0        # estimate mean length of last age class
       1  14   0        # estimate K
PHASE1
fi
#exit
# ---------
#  PHASE 2 
# ---------
if [ ! -f 02.par ]; then
  ./mfcl.exe albN.frq 01.par 02.par -file - <<PHASE2
     1   1 300        # Max number of function evaluation
     1  50   -3       # set convergence criterion to 1E-03
  -999   3  10        # all selectivities equal for age class 10 and older
  -999  27   1        # estimate seasonal component of catchability
  -999  48   1        # estimate selectivity 
     1 149  20        # set penalty on recruitment devs to 20/10
#     1  12   0        # fix k
     1  13   0        # fix 1st size at age
     1  14   0        # fix last one
PHASE2
fi
#exit
# ---------
#  PHASE 3 
# ---------
if [ ! -f 03.par ]; then
  ./mfcl.exe albN.frq 02.par 03.par -file - <<PHASE3
     2  70   1        # activate parameters and turn on
     2  71   1        # estimation of temporal changes in recruitment distribution
     2 110   5        # penalty weight for deviations
    1 16   1         # est length dep sd
PHASE3
fi
#exit
#  ---------
#   PHASE 4
#  ---------
if [ ! -f 04.par ]; then
 ./mfcl.exe albN.frq 03.par 04.par -file - <<PHASE4
    1  12   1        # estimate mean length 1st age class 
PHASE4
fi
#exit
#  ---------
#   PHASE 5
#  ---------
if [ ! -f 05.par ]; then
 ./mfcl.exe albN.frq 04.par 05.par -file - <<PHASE5
    1 173  2         # est independent mean lengths for first 2 ages
    1 182  10         # penalty weight for deviations
PHASE5
fi
#exit
#  ---------
#   PHASE 6   
#  ---------
if [ ! -f 06.par ]; then
 ./mfcl.exe albN.frq 05.par 06.par -file - <<PHASE6
    1   1 1000       # Max number of fuction evaluation to be 1000
#  Time series changes in catchability (in This run Tai LL CPUE fix catchability; fixed catchability surface fisheries)
   -4  10   1   -4  23  23     # estimate time series change in catchability and random walk every 23 months as series is considered poor
 #  -5  10   1   -5  23  23
 #  -6  10   1   -6  23  23     # estimate "
 #  -7  10   1   -7  23  23     # estimate "
   -999 15 1	# penalty weight for catchability deviation
   -1 10 0
   -2 10 0
   -3 10 0
   -8 10 0
   -9 10 0
   -10 10 0
   -11 10 0
   -12 10 0
   1   182  10         # penalty wt. for length estimation
PHASE6
fi
#exit
#  ---------
#   PHASE 7
#  ---------
if [ ! -f 07.par ]; then
 ./mfcl.exe albN.frq 06.par 07.par  -file - <<PHASE7
    2 145   1        # estimate Beverton Holt SRR with small penalty
    2 146   1        # SRR parameter active
    2 162 1          # activate fitting of steepness parameter 
    2 163 0 
#    2 147   0       # recruitment lag is 0 quarters
    2 148  3         # base F is average over last 3 years  
    2 155   1        # base F average does not include last 1 year
    2 153 35 #130        # parameters of beta distribution defining prior for
    2 154  21 # 50        # steepness - mode = 0.76, sd = 0.08
    1 149   0        # reduce pens on devs from av. recr (to avoid 2 penalties)
    1   1 10000      # Max number of fuction evaluation to be 10000
    1  50   -5       # set convergence criterion to 1E-05
PHASE7
fi
#./mfcl.exe albN.frq 09.par 09.par  -switch 1 1 145 3  # turn these on for SD report
#./mfcl.exe albN.frq 09.par 09.par  -switch 1 1 145 4  #
#./mfcl.exe albN.frq 09.par 09.par  -switch 1 1 145 5  #
